package com.base.logistics.jdl.request;

import com.base.logistics.config.JdlConfig;
import com.base.logistics.jdl.bean.trace.GetWaybill2CTraceByWaybillCodeRequestParams;
import com.base.logistics.jdl.bean.trace.GetWaybill2cTraceByWaybillCodeResponse;
import com.base.logistics.jdl.bean.trace.QueryTraceRequestParams;
import com.base.logistics.jdl.bean.trace.QueryTraceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <pre>
 * 京东订单轨迹api接口实现
 * </pre>
 * @since 2021-02-21
 */
@Component
public class JdlTraceApiRequest {

    /**
     * 服务接口
     */
    private JdlRequestConfig jdlRequestConfig;

    @Autowired
    public JdlTraceApiRequest(JdlRequestConfig jdlRequestConfig) {
        this.jdlRequestConfig = jdlRequestConfig;
    }

    public QueryTraceResponse queryTrace(QueryTraceRequestParams request) throws Exception {
        JdlConfig config = this.jdlRequestConfig.getConfig();
        request.getQueryDTO().setJosPin(config.getPin());
        request.getQueryDTO().setCustomerCode(config.getCustomerCode());
        return this.jdlRequestConfig.execute(request, QueryTraceResponse.class);
    }

    public GetWaybill2cTraceByWaybillCodeResponse getWaybill2cTraceByWaybillCode(GetWaybill2CTraceByWaybillCodeRequestParams request) throws Exception {
        JdlConfig config = this.jdlRequestConfig.getConfig();
        request.getWaybill2cTraceDto().setTradeCode(config.getCustomerCode());
        return this.jdlRequestConfig.execute(request, GetWaybill2cTraceByWaybillCodeResponse.class);
    }
}
